import 'package:daoyi_ui_admin_getx/app/common/icons/icons_config.dart';
import 'package:daoyi_ui_admin_getx/app/common/utils/random_contrasting_colors_util.dart';
import 'package:daoyi_ui_admin_getx/app/widgets/common_check_button_widget.dart';
import 'package:flutter/material.dart';

class CommonDevelopLanData {
  final String title;
  final int iconPoint;
  final bool isChecked;

  const CommonDevelopLanData(this.title, this.iconPoint, this.isChecked);
}

const List<CommonDevelopLanData> _dataList = [
// {
//       "icon_id": "12904102",
//       "name": "JS",
//       "font_class": "JS",
//       "unicode": "e614",
//       "unicode_decimal": 58900
//     },
  CommonDevelopLanData("JS", 0xe614, false),
//     {
//       "icon_id": "15214522",
//       "name": "net",
//       "font_class": "net",
//       "unicode": "e60e",
//       "unicode_decimal": 58894
//     },
  CommonDevelopLanData(".net", 0xe60e, false),
//     {
//       "icon_id": "19035884",
//       "name": "JSON",
//       "font_class": "JSON",
//       "unicode": "e618",
//       "unicode_decimal": 58904
//     },
  CommonDevelopLanData("JSON", 0xe618, false),
//     {
//       "icon_id": "24181037",
//       "name": "flutter",
//       "font_class": "icons8-flutter",
//       "unicode": "e654",
//       "unicode_decimal": 58964
//     },
  CommonDevelopLanData("Flutter", 0xe654, false),
//     {
//       "icon_id": "24191677",
//       "name": "java",
//       "font_class": "java",
//       "unicode": "e6d7",
//       "unicode_decimal": 59095
//     },
  CommonDevelopLanData("Java", 0xe6d7, false),
//     {
//       "icon_id": "25597687",
//       "name": "Rust-icon",
//       "font_class": "Rust-icon",
//       "unicode": "e62f",
//       "unicode_decimal": 58927
//     },
  CommonDevelopLanData("Rust", 0xe62f, false),
//     {
//       "icon_id": "25944419",
//       "name": "oracle",
//       "font_class": "oracle",
//       "unicode": "e601",
//       "unicode_decimal": 58881
//     },
  CommonDevelopLanData("Oracle", 0xe601, false),
//     {
//       "icon_id": "26169335",
//       "name": "DB2",
//       "font_class": "DB2",
//       "unicode": "e6a4",
//       "unicode_decimal": 59044
//     },
  CommonDevelopLanData("DB2", 0xe6a4, false),
//     {
//       "icon_id": "34065146",
//       "name": "Docker",
//       "font_class": "Docker",
//       "unicode": "e60f",
//       "unicode_decimal": 58895
//     },
  CommonDevelopLanData("Docker", 0xe60f, false),
//     {
//       "icon_id": "37434609",
//       "name": "Mysql",
//       "font_class": "Mysql",
//       "unicode": "e788",
//       "unicode_decimal": 59272
//     },
  CommonDevelopLanData("MySQL", 0xe788, false),
//     {
//       "icon_id": "39981255",
//       "name": "JSP",
//       "font_class": "JSP",
//       "unicode": "e68c",
//       "unicode_decimal": 59020
//     }
  CommonDevelopLanData("JSP", 0xe68c, false),
];

class CommonDevelopLangWidget extends StatefulWidget {
  final ValueChanged<List<CommonDevelopLanData>>? onChanged;

  const CommonDevelopLangWidget({
    super.key,
    this.onChanged,
  });

  @override
  State<CommonDevelopLangWidget> createState() =>
      _CommonDevelopLangWidgetState();
}

class _CommonDevelopLangWidgetState extends State<CommonDevelopLangWidget> {
  List<CommonDevelopLanData> list = _dataList;

  @override
  Widget build(BuildContext context) {
    return Wrap(
      runSpacing: 30,
      children: list
          .map(
            (item) => GestureDetector(
              onTap: () {
                setState(() {
                  list = list
                      .map((innerItem) => innerItem == item
                          ? CommonDevelopLanData(
                              item.title,
                              item.iconPoint,
                              !item.isChecked,
                            )
                          : innerItem)
                      .toList();
                  widget.onChanged?.call(list);
                });
              },
              behavior: HitTestBehavior.translucent,
              child: SizedBox(
                width: MediaQuery.of(context).size.width / 5,
                child: Column(
                  children: [
                    ShaderMask(
                      shaderCallback: (Rect bounds) {
                        return LinearGradient(
                          colors: RandomContrastingColorsUtil
                              .generateHighContrastColors(),
                          begin: Alignment.topLeft,
                          end: Alignment.bottomRight,
                        ).createShader(bounds);
                      },
                      child: Icon(
                        IconData(
                          item.iconPoint,
                          fontFamily: IconsConfig.daoyiGet01,
                        ),
                        size: 40,
                        color:
                            RandomContrastingColorsUtil.generateRandomColor(),
                      ),
                    ),
                    Padding(
                      padding: const EdgeInsets.all(10),
                      child: Text(
                        item.title,
                      ),
                    ),
                    CommonCheckButtonWidget(
                      item.isChecked,
                    ),
                  ],
                ),
              ),
            ),
          )
          .toList(),
    );
  }
}
